package com.tanhua.server.controller;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.CommentService;
import com.tanhua.server.service.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 小视频控制器
 */
@RestController
@Slf4j
public class VideoController {
    @Autowired
    private VideoService videoService;

    @Autowired
    private CommentService commentService;

    /**
     * 接口名称：小视频列表
     * 接口路径：GET/smallVideos
     */
    @GetMapping("smallVideos")
    public ResponseEntity<Object> queryVideoList(Integer page, Integer pagesize) {
        log.info("接口名称：小视频列表");
        PageResult pageResult = videoService.queryVideoList(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 接口名称：视频上传
     * 接口路径：POST/smallVideos
     */
    @PostMapping("smallVideos")
    public ResponseEntity<Object> uploadVideos(MultipartFile videoThumbnail, MultipartFile videoFile) throws Exception {
        log.info("接口名称：视频上传");
        return videoService.uploadVideos(videoThumbnail, videoFile);
    }

    /**
     * 接口名称：视频用户关注
     * 接口路径：POST/smallVideos/:uid/userFocus
     */
    @PostMapping("smallVideos/{uid}/userFocus")
    public ResponseEntity<Object> followUser(@PathVariable Long uid) throws Exception {
        log.info("接口名称：视频用户关注");
        return videoService.followUser(uid);
    }

    /**
     * 接口名称：视频用户关注 - 取消
     * 接口路径：POST/smallVideos/:uid/userUnFocus
     */
    @PostMapping("smallVideos/{uid}/userUnFocus")
    public ResponseEntity<Object> unfollowUser(@PathVariable Long uid) throws Exception {
        log.info("接口名称：视频用户关注 - 取消");
        return videoService.unfollowUser(uid);
    }


    /**
     * 接口名称：视频点赞
     * 接口路径：POST/smallVideos/:id/like
     *
     * @param videoId 视屏ID
     * @return
     */
    @PostMapping("/smallVideos/{id}/like")
    public ResponseEntity<Object> videoLike(@PathVariable("id") String videoId) {
        log.info("接口名称：视频点赞");
        return commentService.videoLike(videoId);
    }

    /**
     * 接口名称：视频点赞 - 取消
     * 接口路径：POST/smallVideos/:id/dislike
     */
    @PostMapping("/smallVideos/{id}/dislike")
    public ResponseEntity<Object> CancelVideoLikes(@PathVariable("id") String videoId) {
        log.info("接口名称：视频点赞 - 取消");
        return commentService.CancelVideoLikes(videoId);
    }
}
